import subprocess
from utils.settings import BASE_DIR

# ui文件
path_ui = BASE_DIR / 'common' / 'ui'
# target
path_py = BASE_DIR / 'core' / 'gui'

path_py.mkdir(exist_ok=True)

for ui_file in path_ui.glob('*.ui'):
    py_filename = f'ui_{ui_file.stem}.py'
    py_file = path_py / py_filename

    try:
        # 使用pyside6-uic命令编译UI文件
        subprocess.run(['pyside6-uic', str(ui_file), '-o', str(py_file)], check=True)
        print(f'编译成功: {py_filename}')
    except subprocess.CalledProcessError as e:
        print(f'编译失败: {ui_file.name}')
        print(f'错误信息: {str(e)}')
    except FileNotFoundError:
        print(f'错误: 找不到pyside6-uic，请确保已安装PySide6')
        print('可以使用以下命令安装：pip install PySide6')
        break
